package com.wzt.lianfirecontrol.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wzt.lianfirecontrol.R;
import com.wzt.lianfirecontrol.bean.recode.DateModel;
import com.wzt.lianfirecontrol.utils.ScreenUtils;

public class DateHistoryAdapter extends BaseRecyclerAdapter<DateModel> {

    private Context context;

    private String currentDataStr;

    public String getCurrentDataStr() {
        return currentDataStr;
    }

    public void setCurrentDataStr(String currentDataStr) {
        this.currentDataStr = currentDataStr;
    }

    public DateHistoryAdapter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_week_view, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, DateModel data) {
        if (viewHolder instanceof MyViewHolder){
            setItemData((MyViewHolder)viewHolder, data, RealPosition);
        }
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{
        private LinearLayout ll_week;
        private TextView tv_week;
        private TextView tv_week_day;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            initItemView(this, itemView);
        }
    }

    private void initItemView(MyViewHolder myViewHolder, View itemView) {
        myViewHolder.ll_week = itemView.findViewById(R.id.ll_week);
        myViewHolder.tv_week = itemView.findViewById(R.id.tv_week);
        myViewHolder.tv_week_day = itemView.findViewById(R.id.tv_week_day);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) myViewHolder.ll_week.getLayoutParams();
        layoutParams.width = ScreenUtils.getScreenWidth(context) / 7;
    }

    private void setItemData(MyViewHolder viewHolder, DateModel data, int position) {
        if (data.getDateStr().equals(currentDataStr)){
            viewHolder.ll_week.setBackgroundColor(context.getResources().getColor(R.color.main_color_tran));
            viewHolder.tv_week.setTextColor(context.getResources().getColor(R.color.main_color));
            viewHolder.tv_week_day.setTextColor(context.getResources().getColor(R.color.main_color));
        }else {
            viewHolder.ll_week.setBackgroundColor(context.getResources().getColor(R.color.transparent));
            viewHolder.tv_week.setTextColor(context.getResources().getColor(R.color.hint_text_color));
            viewHolder.tv_week_day.setTextColor(context.getResources().getColor(R.color.text_color));
        }
        switch (position){
            case 0:
                viewHolder.tv_week.setText("日");
                break;
            case 1:
                viewHolder.tv_week.setText("一");
                break;
            case 2:
                viewHolder.tv_week.setText("二");
                break;
            case 3:
                viewHolder.tv_week.setText("三");
                break;
            case 4:
                viewHolder.tv_week.setText("四");
                break;
            case 5:
                viewHolder.tv_week.setText("五");
                break;
            case 6:
                viewHolder.tv_week.setText("六");
                break;
        }
         viewHolder.tv_week_day.setText(data.getDateStr().substring(5, 10));
    }

}
